package mother_merge;

/**
 * Created by xupeng20 on 2019/1/30.
 */
public class Java_Mother_GetK {
    public static int getK(int[] arr,int L,int R,int k){
        if (L==R||arr.length<2){
            return arr[L];
        }
        if (L>R){
            return arr[L+k-1];
        }
        if (L+k/2-1<=R){
            return arr[L+(k/2)-1];
        }
        return getK(arr,L,R,k-k/2);
    }
    public static void main(String[] args){
        int [] arr = {1,4,3,5,7,8};
        int k = getK(arr, 0, arr.length - 1, 2);
        System.out.println(k);
    }
}
